using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.SimpleTemp.Repositories.Sys;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class PX_ReportCardService : BaseAppService<PX_ReportCardDto, PX_ReportCard , PX_ReportCardRepository>
        {
        readonly ExcelHelp _excelHelp;
        public PX_ReportCardService (PX_ReportCardRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<PX_ReportCard, PX_ReportCardDto>
            GetLoadPageOffsetMode(PagingModel<PX_ReportCardDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("PlanID","=") //
         .Add("trainingcourse","=") //
         .Add("Trainer","=") //
         .Add("TrainingTime","=") //
         .Add("CreateFactory","=") //
         .Add("CreateDept","=") //
         .Add("UpdateDept","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  PX_ReportCard() {
                Id = model.Id,
PlanID= model.PlanID,//
trainingcourse= model.trainingcourse,//
Trainer= model.Trainer,//
TrainingTime= model.TrainingTime,//
CreateFactory= model.CreateFactory,//
CreateDept= model.CreateDept,//
UpdateDept= model.UpdateDept,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<PX_ReportCardDto>> GetList(PagingModel<PX_ReportCardDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<PX_ReportCardDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.PlanID,
PlanID_title ="",
model.trainingcourse,
trainingcourse_title ="",
model.Trainer,
Trainer_title ="",
model.TrainingTime,
TrainingTime_title ="",
model.CreateFactory,
CreateFactory_title ="",
model.CreateDept,
CreateDept_title ="",
model.UpdateDept,
UpdateDept_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
